<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui" template="template.xhtml">
	<head>

	</head>
	<ui:define name="container">
		<h:form prependId="false">
			<p:panel header="Cadastrar questionário" toggleable="true"
				closable="true" toggleSpeed="500">
				<h:panelGrid id="acoes">
					<h:outputLabel value="Código:" />
					<p:inputText disabled="true" style="width: 50px"
						value="#{questionarioMB.questionarioSelecionado.idQuestionario}" />
					<h:outputText value="Questionário:" />
					<p:inputText style="width: 420px"
						disabled="#{questionarioMB.viewState.enable}"
						value="#{questionarioMB.questionarioSelecionado.nomeQuestionario}" />
					<h:panelGroup>
						<p:selectBooleanCheckbox
							disabled="#{questionarioMB.viewState.enable}"
							value="#{questionarioMB.questionarioSelecionado.ativo}" />
						<h:outputLabel value="Ativo" />
					</h:panelGroup>
				</h:panelGrid>

				<h:panelGrid id="lista">
					<p:dataTable id="lstQuestionarios" var="questionario"
						value="#{questionarioMB.listaQuestionarios}" scrollable="true"
						scrollWidth="470" selectionMode="single" scrollHeight="110">

						<p:ajax event="rowSelect" listener="#{questionarioMB.onRowSelect}"
							update="acao,acoes" />


						<p:column style="width: 110px"
							filterBy="#{questionario.idQuestionario}" headerText="Código">
							<h:outputText value="#{questionario.idQuestionario}" />
						</p:column>

						<p:column style="width: 300px"
							filterBy="#{questionario.nomeQuestionario}"
							headerText="Questionário">
							<h:outputText value="#{questionario.nomeQuestionario}" />
						</p:column>
					</p:dataTable>
				</h:panelGrid>
				<h:panelGrid id="acao" columns="6">
					<p:commandButton id="cmdAdicionar" image="cmdAdicionar"
						disabled="#{questionarioMB.viewState.cmdAdicionarDisable}"
						value="Adicionar" update="acoes,acao"
						action="#{questionarioMB.novo}" />
					<p:commandButton id="cmdPerguntas" image="cmdPerguntas"
						disabled="#{questionarioMB.viewState.cmdAlterarDisable}"
						update="manterPerguntasDialog" actionListener="#{questionarioMB.consultarPerguntas}"
						value="Perguntas" oncomplete="manterPerguntasDialog.show()" />
					<p:commandButton id="cmdAlterar" value="Alterar" image="cmdAlterar"
						disabled="#{questionarioMB.viewState.cmdAlterarDisable}"
						update="acoes,acao" action="#{questionarioMB.alterar}" />
					<p:commandButton id="cmdGravar" value="Gravar" image="cmdGravar"
						disabled="#{questionarioMB.viewState.cmdGravarDisable}"
						update="lista,acoes,acao,msgs"
						actionListener="#{questionarioMB.salvar}" />
					<p:commandButton id="cmdExcluir" value="Excluir" image="cmdExcluir"
						disabled="#{questionarioMB.viewState.cmdExcluirdDisable}"
						update="lista,acoes,acao,msgs"
						actionListener="#{questionarioMB.excluir}"
						onclick="if(!confirm('Deseja realmente remover esta questionário?')) {return false;}" />
					<p:button outcome="default.jsf" value="Fechar" image="cmdFechar" />
				</h:panelGrid>
			</p:panel>
		</h:form>
	</ui:define>
	<ui:define name="dialog">
		<h:form prependId="false">
			<p:dialog id="manterPerguntasDialog"
				widgetVar="manterPerguntasDialog" modal="true"
				header="Questionário: #{questionarioMB.questionarioSelecionado.nomeQuestionario}"
				resizable="false" minimizable="true" width="570" height="400">


				<h:panelGrid id="acoesPergunta">
					<h:outputLabel value="Código:" />
					<p:inputText disabled="true" style="width: 50px"
						value="#{questionarioMB.perguntaSelecionada.idPergunta}" />
					<h:outputText value="Pergunta:" />
					<p:inputText style="width: 420px"
						disabled="#{questionarioMB.viewState1.enable}"
						value="#{questionarioMB.perguntaSelecionada.nomePergunta}" />
					<h:outputText value="Descrição:" />
					<p:inputTextarea style="width: 420px"
						disabled="#{questionarioMB.viewState1.enable}"
						value="#{questionarioMB.perguntaSelecionada.descricaoPergunta}" />
					<h:panelGroup>
						<p:selectBooleanCheckbox
							disabled="#{questionarioMB.viewState1.enable}"
							value="#{questionarioMB.perguntaSelecionada.ativo}" />
						<h:outputLabel value="Ativo" />
					</h:panelGroup>
				</h:panelGrid>

				<h:panelGrid id="listaPerguntas">
					<p:dataTable id="lstPerguntas" var="pergunta"
						value="#{questionarioMB.listaPerguntas}" scrollable="true"
						scrollWidth="470" selectionMode="single" scrollHeight="110">

						<p:ajax event="rowSelect" listener="#{questionarioMB.onRowSelectPergunta}"
							update="acoesPergunta,acaoPergunta" />


						<p:column style="width: 110px" filterBy="#{pergunta.sequenciaPergunta}"
							headerText="Sequência:">
							<h:outputText value="#{pergunta.sequenciaPergunta}" />
						</p:column>

						<p:column style="width: 300px" filterBy="#{pergunta.nomePergunta}"
							headerText="Pergunta">
							<h:outputText value="#{pergunta.nomePergunta}" />
						</p:column>
					</p:dataTable>
				</h:panelGrid>
				<h:panelGrid id="acaoPergunta" columns="6">
					<p:commandButton image="cmdAdicionar" value="Adicionar"
						update="acoesPergunta,acaoPergunta" disabled="#{questionarioMB.viewState1.cmdAdicionarDisable}"
						action="#{questionarioMB.novaPergunta}" />
					<p:commandButton image="cmdAlternativas"
						disabled="#{questionarioMB.viewState1.cmdAlterarDisable}" update="manterAlternativasDialog"
						value="Alternativas" actionListener="#{questionarioMB.consultarAlternativas}" oncomplete="manterAlternativasDialog.show()" />
					<p:commandButton value="Alterar" image="cmdAlterar"
						disabled="#{questionarioMB.viewState1.cmdAlterarDisable}"
						update="acoesPergunta,acaoPergunta"
						action="#{questionarioMB.alterarPergunta}" />
					<p:commandButton value="Gravar" image="cmdGravar"
						disabled="#{questionarioMB.viewState1.cmdGravarDisable}"
						update="listaPerguntas,acoesPergunta,acaoPergunta,msgs"
						actionListener="#{questionarioMB.salvarPergunta}" />
					<p:commandButton value="Excluir" image="cmdExcluir"
						disabled="#{questionarioMB.viewState1.cmdExcluirdDisable}"
						update="listaPerguntas,acoesPergunta,acaoPergunta,msgs"
						actionListener="#{questionarioMB.excluirPergunta}"
						onclick="if(!confirm('Deseja realmente remover esta pergunta?')) {return false;}" />
					<p:commandButton value="Fechar" image="cmdFechar"
						onclick="manterPerguntasDialog.hide()" />
				</h:panelGrid>
			</p:dialog>
			
			<p:dialog id="manterAlternativasDialog"
				widgetVar="manterAlternativasDialog"  modal="true"
				header="Pergunta: #{questionarioMB.perguntaSelecionada.nomePergunta}"
				resizable="false" minimizable="true" width="570" height="400">


				<h:panelGrid id="acoesAlternativa">
					<h:outputLabel value="Código:" />
					<p:inputText disabled="true" style="width: 50px"
						value="#{questionarioMB.alternativaSelecionada.idAlternativa}" />
					<h:outputText value="Alternativa:" />
					<p:inputText style="width: 420px"
						disabled="#{questionarioMB.viewState2.enable}"
						value="#{questionarioMB.alternativaSelecionada.nomeAlternativa}" />
					<h:outputText value="Descrição:" />
					<p:selectOneMenu style="width: 230px"
							disabled="#{questionarioMB.viewState2.enable}"
							value="#{questionarioMB.alternativaSelecionada.proximaPergunta.idPergunta}">
							<f:selectItems value="#{questionarioMB.comboPergunta}" />
						</p:selectOneMenu>
					<h:panelGroup>
						<p:selectBooleanCheckbox
							disabled="#{questionarioMB.viewState2.enable}"
							value="#{questionarioMB.alternativaSelecionada.ativa}" />
						<h:outputLabel value="Ativo" />
					</h:panelGroup>
				</h:panelGrid>

				<h:panelGrid id="listaAlternativas">
					<p:dataTable id="lstAlternativas" var="alternativa"
						value="#{questionarioMB.listaAlternativas}" scrollable="true"
						scrollWidth="470" selectionMode="single" scrollHeight="110">

						<p:ajax event="rowSelect" listener="#{questionarioMB.onRowSelectAlternativa}"
							update="acoesAlternativa,acaoAlternativa" />


						<p:column style="width: 110px" filterBy="#{alternativa.sequenciaAlternativa}"
							headerText="Sequência:">
							<h:outputText value="#{alternativa.sequenciaAlternativa}" />
						</p:column>

						<p:column style="width: 300px" filterBy="#{alternativa.nomeAlternativa}"
							headerText="Alternativa">
							<h:outputText value="#{alternativa.nomeAlternativa}" />
						</p:column>
					</p:dataTable>
				</h:panelGrid>
				<h:panelGrid id="acaoAlternativa" columns="6">
					<p:commandButton image="cmdAdicionar" value="Adicionar"
						update="acoesAlternativa,acaoAlternativa" disabled="#{questionarioMB.viewState2.cmdAdicionarDisable}"
						action="#{questionarioMB.novaAlternativa}" />					
					<p:commandButton value="Alterar" image="cmdAlterar"
						disabled="#{questionarioMB.viewState2.cmdAlterarDisable}"
						update="acoesAlternativa,acaoAlternativa"
						action="#{questionarioMB.alterarAlternativa}" />
					<p:commandButton value="Gravar" image="cmdGravar"
						disabled="#{questionarioMB.viewState2.cmdGravarDisable}"
						update="listaAlternativas,acoesAlternativa,acaoAlternativa,msgs"
						actionListener="#{questionarioMB.salvarAlternativa}" />
					<p:commandButton value="Excluir" image="cmdExcluir"
						disabled="#{questionarioMB.viewState2.cmdExcluirdDisable}"
						update="listaAlternativas,acoesAlternativa,acaoAlternativa,msgs"
						actionListener="#{questionarioMB.excluirAlternativa}"
						onclick="if(!confirm('Deseja realmente remover esta alternativa?')) {return false;}" />
					<p:commandButton value="Fechar" image="cmdFechar"
						onclick="manterAlternativasDialog.hide()" />
				</h:panelGrid>
			</p:dialog>
		</h:form>
	</ui:define>
</ui:composition>
